package com.roncoo.eshop.inventory.request;

import com.roncoo.eshop.inventory.model.ProductInventory;
import com.roncoo.eshop.inventory.service.ProductInventoryService;

import lombok.extern.slf4j.Slf4j;

/**
 * Copyright: Copyright (c) 2019 Hu-Cheng
 * 
 * @ClassName: ProductInventoryDBUpdateRequest.java
 * @Description: 库存操作：删除缓存、更新数据库
 *
 * @version: v1.0.0
 * @author: hucheng
 * @date: 2019年9月19日 下午2:48:02
 *
 */
@Slf4j
public class ProductInventoryDBUpdateRequest implements Request {

	/**
	 * 商品库存
	 */
	private ProductInventory productInventory;

	/**
	 * 商品库存service
	 */
	private ProductInventoryService productInventoryService;

	public ProductInventoryDBUpdateRequest(ProductInventory productInventory,
			ProductInventoryService productInventoryService) {
		this.productInventory = productInventory;
		this.productInventoryService = productInventoryService;
	}

	@Override
	public void process() {
		log.info("更新库存 >>>>>> 删除缓存商品id：" + productInventory.getProductId());
		// 删除redis缓存
		productInventoryService.removeProductInventoryCache(productInventory);
		log.info("更新库存 >>>>>> 更新数据库商品id：" + productInventory.getProductId() + "，更新库存："
				+ productInventory.getInventoryCnt());
		// 修改数据库库存
		productInventoryService.updateProductInventory(productInventory);
	}

	/**
	 * 获取商品id
	 */
	@Override
	public Integer getProductId() {
		return productInventory.getProductId();
	}

	@Override
	public Boolean getForceRefresh() {
		return false;
	}

}
